/**
 * 
 */
package rs.fon.rapidminer.process;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Nikola Nikolic
 * 
 *         This class is a utill class that reads all annotated properties form
 *         class
 */
public class ParameterReader {

	/**
	 * 
	 * this method reads annotated properties with
	 * {@link rs.fon.rapidminer.process.annotation.Parameter} form class and
	 * returns List of {@link Parameter} objects.
	 */

	public static List<Parameter> readParameters(Class<?> classType) {
		List<Parameter> list = new ArrayList<Parameter>();

		Field[] fields = classType.getDeclaredFields();
		for (Field field : fields) {
			Annotation[] annotations = field.getAnnotations();
			for (Annotation annotation : annotations) {
				if (annotation.annotationType().equals(
						rs.fon.rapidminer.process.annotation.Parameter.class)) {
					Parameter param = new Parameter();
					param
							.setDefaultValue(((rs.fon.rapidminer.process.annotation.Parameter) annotation)
									.defaultValue());
					param
							.setMinValue(((rs.fon.rapidminer.process.annotation.Parameter) annotation)
									.minValue());
					param
							.setMaxValue(((rs.fon.rapidminer.process.annotation.Parameter) annotation)
									.maxValue());
					param.setNameOfParameter(field.getName());
					param.setParametertType(field.getType());
					list.add(param);

				}
			}
		}

		return list;

	}
}